package com.ukao.steward.pesenter.valetRunners;

import android.util.Log;

import com.ukao.steward.base.BasePresenter;
import com.ukao.steward.bean.BatchClothingBean;
import com.ukao.steward.bean.HttpBean;
import com.ukao.steward.bean.OrderClothingBean;
import com.ukao.steward.consts.Constant;
import com.ukao.steward.consts.SaveParams;
import com.ukao.steward.retrofit.ApiCallback;
import com.ukao.steward.ui.valetRunners.toShop.ToShopFragment;
import com.ukao.steward.view.valetRunners.GoodsToShopDetailsView;

import java.util.HashMap;

import rx.Observable;

/**
 * Created by kefu001 on 2018/4/25.
 */

public class GoodsToShopDetailsPresenter extends BasePresenter<GoodsToShopDetailsView> {

    public GoodsToShopDetailsPresenter(GoodsToShopDetailsView view) {
        super.attachView(view);
    }

    /**
     * 根据列的状态  请求不同的数据
     *  请求批次
     *
     */
    public  void onColumnRequestBatchData(int column, String idCode){
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("outId",idCode);
        mHashMap.put("accessToken", SaveParams.getToken());
        switch (column) {
            case 1:// 共多少件  默认没有
                break;
            case 2://已到店
                mHashMap.put("storeStatus","1");
                break;
            case 3://未到店
                mHashMap.put("storeStatus","0");
                break;
        }
        Log.d("成功+==333", "onSuccess: ");
        Observable observable =apiStores.queryBatchClothesSituation(Constant.createParameter(mHashMap));
        addSubscription(observable,
                new ApiCallback<BatchClothingBean>() {
                    @Override
                    public void onSuccess( BatchClothingBean model) {
                        if (model.getHttpCode() == 200) {
                            Log.d("成功+==3", "onSuccess: ");
                            mvpView.onReceivingBatchDataSucceed(model.getData());
                        }else{
                            mvpView.showError(model.getMsg());
                        }
                    }
                    @Override
                    public void onFinish() {
                        mvpView.onLoadFinish();

                    }
                });

    }

    /**
     *  根据列的状态  请求不同的数据
     *  请求订单的数据
     * @param column
     * @param idCode
     */
    public  void onColumnRequestOrderData(int column, String idCode){
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("orderId",idCode);
        mHashMap.put("accessToken", SaveParams.getToken());
        switch (column) {
            case 1:// 共多少件  默认没有
                break;
            case 2://已到店
                mHashMap.put("isStoreStatus","1");
                break;
            case 3://未到店
                mHashMap.put("isStoreStatus","0");
                break;
        }
        Observable observable =apiStores.queryOrderClothesSituation(Constant.createParameter(mHashMap));
        addSubscription(observable,
                new ApiCallback<OrderClothingBean>() {
                    @Override
                    public void onSuccess(OrderClothingBean model) {
                        if (model.getHttpCode() == 200) {
                            Log.d("成功+==3", "onSuccess: ");
                            mvpView.onReceivingOrderDataSucceed(model.getData());
                        }else{
                            mvpView.showError(model.getMsg());
                        }
                    }
                    @Override
                    public void onFinish() {
                        mvpView.onLoadFinish();  //结束刷新
                    }
                });
    }

    /**
     *   请求衣物商品全部到店
     */
    public   void  onRequestClothingGoodsReceiving(int dataLoadMode,String idCode){
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("accessToken", SaveParams.getToken());
        Observable observable=null;
         switch (dataLoadMode){
             case ToShopFragment.BATCH_TO_SHOP_FLAG:  //批次的
                 mHashMap.put("outId",idCode);
                 observable =apiStores.batchClothesAllToShop(Constant.createParameter(mHashMap));
                 break;
             case ToShopFragment.ORDER_TO_SHOP_FLAG:   //订单的
                 mHashMap.put("orderId",idCode);
                 observable =apiStores.orderClothesAllToShop(Constant.createParameter(mHashMap));
                 break;
         }
        addSubscription(observable,
                new ApiCallback<HttpBean>() {
                    @Override
                    public void onSuccess(HttpBean model) {
                                 if (model.getHttpCode() == 200) {
                                    mvpView.onRefreshData();
                                 }else{
                                     mvpView.showError(model.getMsg());
                                     mvpView.onRequestFailed();
                                 }
                    }
                    @Override
                    public void onFinish() {

                    }
                });
    }

    /**
     * @param oddNumbersId  单号id
     *  请求单个衣服商品收货
     * @param idCode  一条数据的唯一id
     */
    public   void onRequestSingleClothingGoodsReceiving(int dataLoadMode,String oddNumbersId ,String idCode){
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("accessToken", SaveParams.getToken());
        mHashMap.put("id",idCode);
        Observable observable=null;
        switch (dataLoadMode){
            case ToShopFragment.BATCH_TO_SHOP_FLAG:  //批次的
                mHashMap.put("outId",oddNumbersId);
                observable =apiStores.batchClothesAllToShop(Constant.createParameter(mHashMap));
                break;
            case ToShopFragment.ORDER_TO_SHOP_FLAG:   //订单的
                observable =apiStores.orderClothesAllToShop(Constant.createParameter(mHashMap));
                break;
        }
        addSubscription(observable,
                new ApiCallback<HttpBean>() {
                    @Override
                    public void onSuccess(HttpBean model) {
                        if (model.getHttpCode() == 200) {
                            mvpView.onRefreshData();
                        }else{
                            mvpView.showError(model.getMsg());
                            mvpView.onRequestFailed();
                        }
                    }
                    @Override
                    public void onFinish() {

                    }
                });
    }

}
